package com.LA_houseLease.admin.schedule;

import com.LA_houseLease.admin.service.LeaseAgreementService;
import com.LA_houseLease.pojo.entity.LeaseAgreement;
import com.LA_houseLease.pojo.enums.LeaseStatus;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;

@Slf4j
@Component
public class ScheduledTasks {

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    @Scheduled(cron = "0 0 0 * * *")
    public void checkLeaseStatus(){
      log.warn("定时任务：。。。。。定时检查租约状态");
        LambdaUpdateWrapper<LeaseAgreement> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.le(LeaseAgreement::getLeaseEndDate, new Date());
        lambdaUpdateWrapper.in(LeaseAgreement::getStatus, LeaseStatus.SIGNED,LeaseStatus.WITHDRAWING);
        lambdaUpdateWrapper.set(LeaseAgreement::getStatus,LeaseStatus.EXPIRED);
        leaseAgreementService.update(lambdaUpdateWrapper);
    }

    //@Scheduled(cron = "* * * * * * ")
    //public void test(){
    //    log.warn("当前时间{}",new Date());
    //}

}
